/*
 * Copyright (c) 2006-2023, RT-Thread Development Team
 *
 * SPDX-License-Identifier: Apache-2.0
 *
 * Change Logs:
 * Date           Author       Notes
 * 2018-08-24     yangjie      the first version
 */

/*
* 程序清单：定时器例程
*
* 这个例程会创建两个动态定时器，一个是单次定时，一个是周期性定时
* 并让周期定时器运行一段时间后停止运行
*/
#include <aos/aos.h>
#include "aos/cli.h"
#include <debug/dbg.h>

/* 定时器的控制块 */
static aos_timer_t timer1;
static aos_timer_t timer2;
static int cnt = 0;

/* 定时器1超时函数 */
static void timeout1(void *arg1, void* arg2)
{
    aos_debug_printf("periodic timer is timeout %d\n", cnt);

    /* 运行第10次，停止周期定时器 */
    if (cnt++ >= 9)
    {
        aos_timer_stop(&timer1);
        aos_debug_printf("periodic timer was stopped! \n");
    }
}

/* 定时器2超时函数 */
static void timeout2(void *arg1, void* arg2)
{
    aos_debug_printf("one shot timer is timeout\n");
}

int yoc_timer_sample(int argc, char **argv)
{
    int result;
    /* 创建定时器1  周期定时器 */
    aos_timer_new(&timer1,
                 timeout1,
                 NULL,
                 10,
                 1);

    /* 创建定时器2 单次定时器 */
    aos_timer_new(&timer2,
                 timeout2,
                 NULL,
                 30,
                 0);

    return 0;
}

ALIOS_CLI_CMD_REGISTER(yoc_timer_sample, yoc_timer_sample,yoc timer sample);

